package com.platform.data.handle.converter.impl;

import com.platform.data.common.CommonConstant;
import com.platform.data.handle.converter.DataTypeEnum;
import com.platform.data.handle.converter.AbstractDataTypeProcessHandler;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 数组[字符串]
 *
 * @author zhuweijun
 * @version 1.0.0
 * @since 2025/5/13 16:22
 */
public class ArrayStringTypeProcessHandler extends AbstractDataTypeProcessHandler {

    /**
     * 数组[字符串]
     *
     * @param typeEnum typeEnum
     * @param fieldName fieldName
     * @param fieldValue fieldValue
     * @return {@link Object}
     */
    @Override
    public Object process(DataTypeEnum typeEnum, String fieldName, String fieldValue) {
        List<String> stringList = new ArrayList<>();

        // 若有中文逗号，替换为引文逗号，进行切割
        if(fieldValue.contains(CommonConstant.COMMA_CN_CHARACTER)){
            fieldValue = fieldValue.replace(CommonConstant.COMMA_CN_CHARACTER, CommonConstant.COMMA_EH_CHARACTER);
        }

        String[] splitArray = fieldValue.split(CommonConstant.COMMA_EH_CHARACTER);
        for (String value : splitArray) {
            if(StringUtils.isNotBlank(value)){
                stringList.add(value.trim());
            }
        }
        return stringList;
    }
}
